package com.dashuaibran.joker.ui;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dashuaibran.joker.dao.IUserDao;
import com.dashuaibran.joker.factory.BeanFactory;
import com.dashuaibran.joker.service.IUserService;
import com.dashuaibran.joker.service.mysqlimpl.ConstructorArgUserService;
import com.dashuaibran.joker.service.mysqlimpl.ListUserService;
import com.dashuaibran.joker.service.mysqlimpl.SetUserService;

public class Client {
	public static void main(String[] args) throws Exception {
		for (int i = 0; i < 5; i++) {
			IUserService userService = (IUserService) BeanFactory.getBeanSingle("UserService");
			System.out.println(userService);
		}

		// 1.获取核心容器对象
		ApplicationContext aContext = new ClassPathXmlApplicationContext("bean.xml");
		IUserDao userDao = aContext.getBean("UserDao", IUserDao.class);
		IUserService userService = aContext.getBean("UserService", IUserService.class);

		System.out.println(userDao);
		System.out.println(userService);
		userService.find();

		IUserService userService2 = aContext.getBean("InnerFactoryUserService", IUserService.class);
		System.out.println(userService2);

		IUserService userService3 = aContext.getBean("StaticFactoryUserService", IUserService.class);
		System.out.println(userService3);

		IUserService ScopeUserService1 = aContext.getBean("ScopeUserService", IUserService.class);
		IUserService ScopeUserService2 = aContext.getBean("ScopeUserService", IUserService.class);
		System.out.println(ScopeUserService1);
		System.out.println(ScopeUserService2);

		ConstructorArgUserService cons = aContext.getBean("ConstructorArgUserService", ConstructorArgUserService.class);
		cons.printArg();

		SetUserService setUserService = aContext.getBean("SetUserService", SetUserService.class);
		setUserService.printArg();

		ListUserService listUserService = aContext.getBean("ListUserService", ListUserService.class);
		listUserService.printArg();

		IUserService annotationUserService = aContext.getBean("annotationUserService", IUserService.class);
		annotationUserService.find();

	}
}
